{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-02-09T08:38:25.034100Z",
     "start_time": "2025-02-09T08:38:24.598396Z"
    }
   },
   "source": [
    "import numpy as np\n",
    "import random\n",
    "import time"
   ],
   "outputs": [],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.549276Z",
     "start_time": "2025-01-10T08:50:13.545978Z"
    }
   },
   "cell_type": "code",
   "source": [
    "list1 = [1, 2, 3, 4]\n",
    "print(list1)\n",
    "print(type(list1))\n",
    "oneArray = np.array(list1)\n",
    "print(type(oneArray)) \n",
    "print(oneArray)"
   ],
   "id": "a1892e9d8188645c",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4]\n",
      "<class 'list'>\n",
      "<class 'numpy.ndarray'>\n",
      "[1 2 3 4]\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-09T08:38:41.492371Z",
     "start_time": "2025-02-09T08:38:29.232280Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a = []\n",
    "for i in range(100000000):\n",
    "    a.append(random.random())\n",
    "print('随机完毕')\n",
    "b = np.array(a)\n",
    "print('转换完毕')\n",
    "t1 = time.time()\n",
    "sum1 = sum(a)\n",
    "t2 = time.time()\n",
    "t4 = time.time()\n",
    "sum3 = np.sum(b)\n",
    "t5 = time.time()\n",
    "print(t2 - t1, t5 - t4)"
   ],
   "id": "316103118f04594a",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "随机完毕\n",
      "转换完毕\n",
      "0.5598516464233398 0.13634991645812988\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.556650Z",
     "start_time": "2025-01-10T08:50:13.552969Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t3 = np.arange(0, 10, 2)\n",
    "print(t3)\n",
    "print(type(t3))"
   ],
   "id": "984a60e99542317",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 2 4 6 8]\n",
      "<class 'numpy.ndarray'>\n"
     ]
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.560692Z",
     "start_time": "2025-01-10T08:50:13.557652Z"
    }
   },
   "cell_type": "code",
   "source": [
    "list2 = [[1, 2], [3, 4], [5, 6]]\n",
    "twoArray = np.array(list2)\n",
    "print(type(twoArray))\n",
    "print(twoArray)\n",
    "print(list2)"
   ],
   "id": "efec0e75622b1ec6",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.ndarray'>\n",
      "[[1 2]\n",
      " [3 4]\n",
      " [5 6]]\n",
      "[[1, 2], [3, 4], [5, 6]]\n"
     ]
    }
   ],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.563547Z",
     "start_time": "2025-01-10T08:50:13.560692Z"
    }
   },
   "cell_type": "code",
   "source": "# twoArray.tolist()",
   "id": "6743c1f86383d920",
   "outputs": [],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.567053Z",
     "start_time": "2025-01-10T08:50:13.563547Z"
    }
   },
   "cell_type": "code",
   "source": [
    "print(twoArray.ndim)\n",
    "print(twoArray.shape)\n",
    "print(twoArray.size)\n",
    "print(twoArray.dtype)"
   ],
   "id": "5ff366f110325560",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "(3, 2)\n",
      "6\n",
      "int64\n"
     ]
    }
   ],
   "execution_count": 7
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.570849Z",
     "start_time": "2025-01-10T08:50:13.567053Z"
    }
   },
   "cell_type": "code",
   "source": [
    "four = np.array([[1, 2, 3], [4, 5, 6]])\n",
    "print(four)\n",
    "four1 = four\n",
    "print(id(four))\n",
    "four.shape = (3, 2)\n",
    "print(id(four))\n",
    "print(id(four1))\n",
    "print(four)"
   ],
   "id": "bbf86a194fc769b9",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]]\n",
      "1802621180432\n",
      "1802621180432\n",
      "1802621180432\n",
      "[[1 2]\n",
      " [3 4]\n",
      " [5 6]]\n"
     ]
    }
   ],
   "execution_count": 8
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.576251Z",
     "start_time": "2025-01-10T08:50:13.570849Z"
    }
   },
   "cell_type": "code",
   "source": [
    "four2 = four.reshape(2, 3)\n",
    "print(four)\n",
    "print(id(four))\n",
    "print(id(four2))\n",
    "print(four2)\n",
    "four2"
   ],
   "id": "82c6166660a35368",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2]\n",
      " [3 4]\n",
      " [5 6]]\n",
      "1802621180432\n",
      "1802621180624\n",
      "[[1 2 3]\n",
      " [4 5 6]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 9
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.579705Z",
     "start_time": "2025-01-10T08:50:13.576251Z"
    }
   },
   "cell_type": "code",
   "source": [
    "five = four.reshape((6,), order='C')\n",
    "six = four.flatten()\n",
    "print(five)\n",
    "print('-' * 50)\n",
    "print(six)"
   ],
   "id": "9737f90373a43c7e",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3 4 5 6]\n",
      "--------------------------------------------------\n",
      "[1 2 3 4 5 6]\n"
     ]
    }
   ],
   "execution_count": 10
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.583530Z",
     "start_time": "2025-01-10T08:50:13.580707Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t = np.arange(24)\n",
    "print(t)\n",
    "print(f'shape{t.shape}')\n",
    "print(t.ndim)\n",
    "t1 = t.reshape((4, 6))\n",
    "print(t1)\n",
    "print(t1.shape)"
   ],
   "id": "fe6c572ba17943e4",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23]\n",
      "shape(24,)\n",
      "1\n",
      "[[ 0  1  2  3  4  5]\n",
      " [ 6  7  8  9 10 11]\n",
      " [12 13 14 15 16 17]\n",
      " [18 19 20 21 22 23]]\n",
      "(4, 6)\n"
     ]
    }
   ],
   "execution_count": 11
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.586963Z",
     "start_time": "2025-01-10T08:50:13.583530Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t2 = t.reshape((2, 3, 4))\n",
    "print(t2)\n",
    "print(t2.shape)\n",
    "print(t2.ndim)"
   ],
   "id": "3ba7911735dc1600",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[ 0  1  2  3]\n",
      "  [ 4  5  6  7]\n",
      "  [ 8  9 10 11]]\n",
      "\n",
      " [[12 13 14 15]\n",
      "  [16 17 18 19]\n",
      "  [20 21 22 23]]]\n",
      "(2, 3, 4)\n",
      "3\n"
     ]
    }
   ],
   "execution_count": 12
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.590547Z",
     "start_time": "2025-01-10T08:50:13.586963Z"
    }
   },
   "cell_type": "code",
   "source": [
    "f = np.array([1, 2, 3, 4, 127], dtype=np.int8)\n",
    "print(f.itemsize)\n",
    "print(f.dtype)"
   ],
   "id": "fe47c7bf5f636740",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "int8\n"
     ]
    }
   ],
   "execution_count": 13
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.595588Z",
     "start_time": "2025-01-10T08:50:13.592544Z"
    }
   },
   "cell_type": "code",
   "source": [
    "print(round(random.random(), 2))\n",
    "arr = np.array([random.random() for i in range(10)])\n",
    "print(arr)\n",
    "print(arr.itemsize)\n",
    "print(arr.dtype)\n",
    "print(np.round(arr, 2))"
   ],
   "id": "2097bf8606ba9ec",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.09\n",
      "[0.67750337 0.80230123 0.87123684 0.54284504 0.33803265 0.92617554\n",
      " 0.19691618 0.13952063 0.18409325 0.21890539]\n",
      "8\n",
      "float64\n",
      "[0.68 0.8  0.87 0.54 0.34 0.93 0.2  0.14 0.18 0.22]\n"
     ]
    }
   ],
   "execution_count": 14
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.603309Z",
     "start_time": "2025-01-10T08:50:13.595588Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t1 = np.arange(24).reshape((6, 4))\n",
    "print(t1)\n",
    "print(\"-\" * 20)\n",
    "t2 = t1.tolist()\n",
    "print(t1 + 2)\n",
    "print(\"-\" * 20)\n",
    "print(t1 * 2)\n",
    "print(\"-\" * 20)\n",
    "print(t1 / 2)"
   ],
   "id": "c9903ff3e1ce8869",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3]\n",
      " [ 4  5  6  7]\n",
      " [ 8  9 10 11]\n",
      " [12 13 14 15]\n",
      " [16 17 18 19]\n",
      " [20 21 22 23]]\n",
      "--------------------\n",
      "[[ 2  3  4  5]\n",
      " [ 6  7  8  9]\n",
      " [10 11 12 13]\n",
      " [14 15 16 17]\n",
      " [18 19 20 21]\n",
      " [22 23 24 25]]\n",
      "--------------------\n",
      "[[ 0  2  4  6]\n",
      " [ 8 10 12 14]\n",
      " [16 18 20 22]\n",
      " [24 26 28 30]\n",
      " [32 34 36 38]\n",
      " [40 42 44 46]]\n",
      "--------------------\n",
      "[[ 0.   0.5  1.   1.5]\n",
      " [ 2.   2.5  3.   3.5]\n",
      " [ 4.   4.5  5.   5.5]\n",
      " [ 6.   6.5  7.   7.5]\n",
      " [ 8.   8.5  9.   9.5]\n",
      " [10.  10.5 11.  11.5]]\n"
     ]
    }
   ],
   "execution_count": 15
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.607585Z",
     "start_time": "2025-01-10T08:50:13.603309Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t1 = np.arange(24).reshape((4, 6))\n",
    "t2 = np.arange(4).reshape((4, 1))\n",
    "print(t2)\n",
    "print(t1)\n",
    "t1 - t2"
   ],
   "id": "9e94b4590fde1392",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0]\n",
      " [1]\n",
      " [2]\n",
      " [3]]\n",
      "[[ 0  1  2  3  4  5]\n",
      " [ 6  7  8  9 10 11]\n",
      " [12 13 14 15 16 17]\n",
      " [18 19 20 21 22 23]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4,  5],\n",
       "       [ 5,  6,  7,  8,  9, 10],\n",
       "       [10, 11, 12, 13, 14, 15],\n",
       "       [15, 16, 17, 18, 19, 20]])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 16
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.611929Z",
     "start_time": "2025-01-10T08:50:13.607585Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a = np.array([[1, 2, 3], [4, 5, 6]])\n",
    "print(a)\n",
    "print(\"-\" * 20)\n",
    "print(np.sum(a, axis=0))\n",
    "print(\"-\" * 20)\n",
    "print(np.sum(a, axis=1))\n",
    "print(np.sum(a))\n",
    "print(\"-\" * 20)"
   ],
   "id": "72b7510a26fdaefc",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]]\n",
      "--------------------\n",
      "[5 7 9]\n",
      "--------------------\n",
      "[ 6 15]\n",
      "21\n",
      "--------------------\n"
     ]
    }
   ],
   "execution_count": 17
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.615735Z",
     "start_time": "2025-01-10T08:50:13.611929Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a = np.arange(10)\n",
    "print(a[0], a)\n",
    "print(a[2:])\n",
    "print(a[2:8:2])"
   ],
   "id": "7419905b872761af",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 [0 1 2 3 4 5 6 7 8 9]\n",
      "[2 3 4 5 6 7 8 9]\n",
      "[2 4 6]\n"
     ]
    }
   ],
   "execution_count": 18
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.620009Z",
     "start_time": "2025-01-10T08:50:13.616736Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t1 = np.arange(24).reshape(4, 6)\n",
    "print(t1)\n",
    "print('*' * 20)\n",
    "print(t1[1])\n",
    "print('*' * 20)\n",
    "print(t1[1:])\n",
    "print('*' * 20)\n",
    "print(t1[1:3])\n",
    "print('*' * 20)\n",
    "print(t1[[0, 2, 3]])"
   ],
   "id": "b45f8f4e371962ba",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3  4  5]\n",
      " [ 6  7  8  9 10 11]\n",
      " [12 13 14 15 16 17]\n",
      " [18 19 20 21 22 23]]\n",
      "********************\n",
      "[ 6  7  8  9 10 11]\n",
      "********************\n",
      "[[ 6  7  8  9 10 11]\n",
      " [12 13 14 15 16 17]\n",
      " [18 19 20 21 22 23]]\n",
      "********************\n",
      "[[ 6  7  8  9 10 11]\n",
      " [12 13 14 15 16 17]]\n",
      "********************\n",
      "[[ 0  1  2  3  4  5]\n",
      " [12 13 14 15 16 17]\n",
      " [18 19 20 21 22 23]]\n"
     ]
    }
   ],
   "execution_count": 19
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.624707Z",
     "start_time": "2025-01-10T08:50:13.620009Z"
    }
   },
   "cell_type": "code",
   "source": [
    "print(t1[:, 1])\n",
    "print('*' * 20)\n",
    "print(t1[:, 1:])\n",
    "print('*' * 20)\n",
    "print(t1[:, [0, 2, 3]])\n",
    "print('*' * 20)\n",
    "print(t1[2, 3])\n",
    "print('*' * 20)\n",
    "print(t1[[0, 1, 1], [0, 1, 3]])\n",
    "t1[1:3, 1:4]"
   ],
   "id": "b2495534332ac026",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 1  7 13 19]\n",
      "********************\n",
      "[[ 1  2  3  4  5]\n",
      " [ 7  8  9 10 11]\n",
      " [13 14 15 16 17]\n",
      " [19 20 21 22 23]]\n",
      "********************\n",
      "[[ 0  2  3]\n",
      " [ 6  8  9]\n",
      " [12 14 15]\n",
      " [18 20 21]]\n",
      "********************\n",
      "15\n",
      "********************\n",
      "[0 7 9]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[ 7,  8,  9],\n",
       "       [13, 14, 15]])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 20
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.628752Z",
     "start_time": "2025-01-10T08:50:13.624707Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t = np.arange(24).reshape(4, 6)\n",
    "print(t)\n",
    "print(id(t))\n",
    "print('-' * 50)\n",
    "t[1, :] = 0\n",
    "print(id(t))\n",
    "print(t)\n",
    "print('-' * 50)"
   ],
   "id": "9e4d68b2c2209df0",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3  4  5]\n",
      " [ 6  7  8  9 10 11]\n",
      " [12 13 14 15 16 17]\n",
      " [18 19 20 21 22 23]]\n",
      "1802621182544\n",
      "--------------------------------------------------\n",
      "1802621182544\n",
      "[[ 0  1  2  3  4  5]\n",
      " [ 0  0  0  0  0  0]\n",
      " [12 13 14 15 16 17]\n",
      " [18 19 20 21 22 23]]\n",
      "--------------------------------------------------\n"
     ]
    }
   ],
   "execution_count": 21
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.632080Z",
     "start_time": "2025-01-10T08:50:13.628752Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t[:, 1] = 0\n",
    "print(id(t))\n",
    "print(t)\n",
    "print('-' * 50)"
   ],
   "id": "2366e3cc65411c4d",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1802621182544\n",
      "[[ 0  0  2  3  4  5]\n",
      " [ 0  0  0  0  0  0]\n",
      " [12  0 14 15 16 17]\n",
      " [18  0 20 21 22 23]]\n",
      "--------------------------------------------------\n"
     ]
    }
   ],
   "execution_count": 22
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.635523Z",
     "start_time": "2025-01-10T08:50:13.632080Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t[1:3, :] = 0\n",
    "print(id(t))\n",
    "print(t)\n",
    "print('-' * 50)"
   ],
   "id": "d57fe4d255e66a3f",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1802621182544\n",
      "[[ 0  0  2  3  4  5]\n",
      " [ 0  0  0  0  0  0]\n",
      " [ 0  0  0  0  0  0]\n",
      " [18  0 20 21 22 23]]\n",
      "--------------------------------------------------\n"
     ]
    }
   ],
   "execution_count": 23
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.638671Z",
     "start_time": "2025-01-10T08:50:13.635523Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t[:, 1:4] = 0\n",
    "print(id(t))\n",
    "print(t)\n",
    "print('-' * 50)"
   ],
   "id": "7e39030b2fae48f4",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1802621182544\n",
      "[[ 0  0  0  0  4  5]\n",
      " [ 0  0  0  0  0  0]\n",
      " [ 0  0  0  0  0  0]\n",
      " [18  0  0  0 22 23]]\n",
      "--------------------------------------------------\n"
     ]
    }
   ],
   "execution_count": 24
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.642481Z",
     "start_time": "2025-01-10T08:50:13.638671Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t = np.arange(24).reshape(4, 6)\n",
    "print(t)\n",
    "print(id(t))\n",
    "print('-' * 50)\n",
    "t[1:3, 2:5] = 0\n",
    "print(id(t))\n",
    "print(t)\n",
    "print('-' * 50)"
   ],
   "id": "40969f288b2d39ba",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3  4  5]\n",
      " [ 6  7  8  9 10 11]\n",
      " [12 13 14 15 16 17]\n",
      " [18 19 20 21 22 23]]\n",
      "1802621182448\n",
      "--------------------------------------------------\n",
      "1802621182448\n",
      "[[ 0  1  2  3  4  5]\n",
      " [ 6  7  0  0  0 11]\n",
      " [12 13  0  0  0 17]\n",
      " [18 19 20 21 22 23]]\n",
      "--------------------------------------------------\n"
     ]
    }
   ],
   "execution_count": 25
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.646279Z",
     "start_time": "2025-01-10T08:50:13.643483Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t[[0, 1], [1, 3]] = 0\n",
    "print(id(t))\n",
    "print(t)\n",
    "print('-' * 50)"
   ],
   "id": "1f01248bb01f15e7",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1802621182448\n",
      "[[ 0  0  2  3  4  5]\n",
      " [ 6  7  0  0  0 11]\n",
      " [12 13  0  0  0 17]\n",
      " [18 19 20 21 22 23]]\n",
      "--------------------------------------------------\n"
     ]
    }
   ],
   "execution_count": 26
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.649761Z",
     "start_time": "2025-01-10T08:50:13.646279Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t = np.arange(24).reshape(4, 6)\n",
    "# t[t<10]=0\n",
    "# t[(t>2)&(t<6)]=0\t\n",
    "# t[(t<2)|(t>6)]=0\t\n",
    "t[~(t > 6)] = 0\n",
    "print(t)"
   ],
   "id": "47b9dab963c625af",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  0  0  0  0  0]\n",
      " [ 0  7  8  9 10 11]\n",
      " [12 13 14 15 16 17]\n",
      " [18 19 20 21 22 23]]\n"
     ]
    }
   ],
   "execution_count": 27
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.654250Z",
     "start_time": "2025-01-10T08:50:13.650762Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a = 10\n",
    "b = 15\n",
    "c = a if a > b else b\n",
    "c"
   ],
   "id": "d3785a2ea801edd9",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "15"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 28
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:13.799031Z",
     "start_time": "2025-01-10T08:50:13.795283Z"
    }
   },
   "cell_type": "code",
   "source": [
    "score = np.array([[80, 88], [82, 81], [75, 81]])\n",
    "print(score)\n",
    "result = np.where(score < 80, True, False)\n",
    "print(result)"
   ],
   "id": "e91546c008400c8",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[80 88]\n",
      " [82 81]\n",
      " [75 81]]\n",
      "[[False False]\n",
      " [False False]\n",
      " [ True False]]\n"
     ]
    }
   ],
   "execution_count": 29
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:14.012826Z",
     "start_time": "2025-01-10T08:50:14.009075Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a = np.array([[1, 2, 3], [4, 5, 6]])\n",
    "\n",
    "print('第一个数组：')\n",
    "print(a)\n",
    "print(' 向 数 组 添 加 元 素 ：')\n",
    "print(np.append(a, [7, 8, 9]))\n",
    "print(a)\n",
    "print('-' * 50)"
   ],
   "id": "d8030f4388cb2dcf",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "第一个数组：\n",
      "[[1 2 3]\n",
      " [4 5 6]]\n",
      " 向 数 组 添 加 元 素 ：\n",
      "[1 2 3 4 5 6 7 8 9]\n",
      "[[1 2 3]\n",
      " [4 5 6]]\n",
      "--------------------------------------------------\n"
     ]
    }
   ],
   "execution_count": 30
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:14.123170Z",
     "start_time": "2025-01-10T08:50:14.118852Z"
    }
   },
   "cell_type": "code",
   "source": [
    "print('沿轴 0 添加元素：')\n",
    "print(np.append(a, [[7, 8, 9]], axis=0))\n",
    "print('-' * 50)\n",
    "print('沿轴 1 添加元素：')\n",
    "print(np.append(a, [[5, 5, 5], [7, 8, 9]], axis=1))\n",
    "print('-' * 50)\n",
    "print(a)"
   ],
   "id": "e9eb0fbdf3a911d7",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "沿轴 0 添加元素：\n",
      "[[1 2 3]\n",
      " [4 5 6]\n",
      " [7 8 9]]\n",
      "--------------------------------------------------\n",
      "沿轴 1 添加元素：\n",
      "[[1 2 3 5 5 5]\n",
      " [4 5 6 7 8 9]]\n",
      "--------------------------------------------------\n",
      "[[1 2 3]\n",
      " [4 5 6]]\n"
     ]
    }
   ],
   "execution_count": 31
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:14.166741Z",
     "start_time": "2025-01-10T08:50:14.162181Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a = np.array([[1, 2], [3, 4], [5, 6]])\n",
    "print('第一个数组：')\n",
    "print(a)\n",
    "print('未传递 Axis 参数。 在插入之前输入数组会被展开。')\n",
    "print(np.insert(a, 1, [11, 22]))\n",
    "print('-' * 50)"
   ],
   "id": "7b09e15b91f99abc",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "第一个数组：\n",
      "[[1 2]\n",
      " [3 4]\n",
      " [5 6]]\n",
      "未传递 Axis 参数。 在插入之前输入数组会被展开。\n",
      "[ 1 11 22  2  3  4  5  6]\n",
      "--------------------------------------------------\n"
     ]
    }
   ],
   "execution_count": 32
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:14.198381Z",
     "start_time": "2025-01-10T08:50:14.194749Z"
    }
   },
   "cell_type": "code",
   "source": "print(np.insert(a, 1, [11, 12], axis=0))",
   "id": "7bff55e51345853a",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1  2]\n",
      " [11 12]\n",
      " [ 3  4]\n",
      " [ 5  6]]\n"
     ]
    }
   ],
   "execution_count": 33
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:14.242447Z",
     "start_time": "2025-01-10T08:50:14.239386Z"
    }
   },
   "cell_type": "code",
   "source": [
    "print('沿轴  0 广播：')\n",
    "print(np.insert(a, 1, 11, axis=0))"
   ],
   "id": "8abb26ebdcf9b6b1",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "沿轴  0 广播：\n",
      "[[ 1  2]\n",
      " [11 11]\n",
      " [ 3  4]\n",
      " [ 5  6]]\n"
     ]
    }
   ],
   "execution_count": 34
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:14.268046Z",
     "start_time": "2025-01-10T08:50:14.264453Z"
    }
   },
   "cell_type": "code",
   "source": [
    "print('沿轴  1 广播：')\n",
    "print(np.insert(a, 1, [1, 2, 5], axis=1))"
   ],
   "id": "2f81777e18547678",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "沿轴  1 广播：\n",
      "[[1 1 2]\n",
      " [3 2 4]\n",
      " [5 5 6]]\n"
     ]
    }
   ],
   "execution_count": 35
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:14.298087Z",
     "start_time": "2025-01-10T08:50:14.294053Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a = np.arange(12).reshape(3, 4)\n",
    "\n",
    "print('第一个数组：')\n",
    "print(a)\n",
    "print('未传递 Axis 参数。 在删除之前输入数组会被展开。')\n",
    "print(np.delete(a, 5))\n",
    "print('删除第一行：')\n",
    "print(np.delete(a, 1, axis=0))\n",
    "print('删除第一列：')\n",
    "print(np.delete(a, 1, axis=1))"
   ],
   "id": "1cbd15a6b6d39a7e",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "第一个数组：\n",
      "[[ 0  1  2  3]\n",
      " [ 4  5  6  7]\n",
      " [ 8  9 10 11]]\n",
      "未传递 Axis 参数。 在删除之前输入数组会被展开。\n",
      "[ 0  1  2  3  4  6  7  8  9 10 11]\n",
      "删除第一行：\n",
      "[[ 0  1  2  3]\n",
      " [ 8  9 10 11]]\n",
      "删除第一列：\n",
      "[[ 0  2  3]\n",
      " [ 4  6  7]\n",
      " [ 8 10 11]]\n"
     ]
    }
   ],
   "execution_count": 36
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:14.322737Z",
     "start_time": "2025-01-10T08:50:14.319087Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a = np.array([5, 2, 6, 2, 7, 5, 6, 9, 8, 2])\n",
    "print('第一个数组：')\n",
    "print(a)\n",
    "print('第一个数组的去重值：')\n",
    "u = np.unique(a)\n",
    "print(u)"
   ],
   "id": "2c705e425f0a95a0",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "第一个数组：\n",
      "[5 2 6 2 7 5 6 9 8 2]\n",
      "第一个数组的去重值：\n",
      "[2 5 6 7 8 9]\n"
     ]
    }
   ],
   "execution_count": 37
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:14.365032Z",
     "start_time": "2025-01-10T08:50:14.361748Z"
    }
   },
   "cell_type": "code",
   "source": [
    "print('去重数组的索引数组：')\n",
    "u, indices = np.unique(a, return_index=True)\n",
    "print(u)\n",
    "print(indices)"
   ],
   "id": "779bd0fed3e0078c",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "去重数组的索引数组：\n",
      "[2 5 6 7 8 9]\n",
      "[1 0 2 4 8 7]\n"
     ]
    }
   ],
   "execution_count": 38
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:14.398638Z",
     "start_time": "2025-01-10T08:50:14.395041Z"
    }
   },
   "cell_type": "code",
   "source": [
    "print('我们可以看到每个和原数组下标对应的数值：')\n",
    "print('去重数组的下标：')\n",
    "u, indices = np.unique(a, return_inverse=True)\n",
    "print(u)\n",
    "print(indices)"
   ],
   "id": "bce3b75bc1201535",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "我们可以看到每个和原数组下标对应的数值：\n",
      "去重数组的下标：\n",
      "[2 5 6 7 8 9]\n",
      "[1 0 2 0 3 1 2 5 4 0]\n"
     ]
    }
   ],
   "execution_count": 39
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:14.440125Z",
     "start_time": "2025-01-10T08:50:14.435634Z"
    }
   },
   "cell_type": "code",
   "source": [
    "print('返回去重元素的重复数量：')\n",
    "u, indices = np.unique(a, return_counts=True)\n",
    "print(u)\n",
    "print(indices)\n",
    "u"
   ],
   "id": "fae33abb1be09ce7",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "返回去重元素的重复数量：\n",
      "[2 5 6 7 8 9]\n",
      "[3 2 2 1 1 1]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([2, 5, 6, 7, 8, 9])"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 40
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:14.453032Z",
     "start_time": "2025-01-10T08:50:14.450130Z"
    }
   },
   "cell_type": "code",
   "source": [
    "score = np.array([[80, 88], [82, 81], [75, 81]])\n",
    "print(score)"
   ],
   "id": "10941afe645eb3bd",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[80 88]\n",
      " [82 81]\n",
      " [75 81]]\n"
     ]
    }
   ],
   "execution_count": 41
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:14.459785Z",
     "start_time": "2025-01-10T08:50:14.457035Z"
    }
   },
   "cell_type": "code",
   "source": [
    "result = np.max(score)\n",
    "print(result)"
   ],
   "id": "346ae52e1c65628b",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "88\n"
     ]
    }
   ],
   "execution_count": 42
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:14.500599Z",
     "start_time": "2025-01-10T08:50:14.497795Z"
    }
   },
   "cell_type": "code",
   "source": [
    "result = np.max(score, axis=1)\n",
    "print(result)"
   ],
   "id": "e8a2f4cb442d093",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[88 82 81]\n"
     ]
    }
   ],
   "execution_count": 43
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:14.516577Z",
     "start_time": "2025-01-10T08:50:14.513597Z"
    }
   },
   "cell_type": "code",
   "source": [
    "result = np.min(score)\n",
    "print(result)"
   ],
   "id": "4a053de0d89ee1f0",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "75\n"
     ]
    }
   ],
   "execution_count": 44
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:14.546455Z",
     "start_time": "2025-01-10T08:50:14.543585Z"
    }
   },
   "cell_type": "code",
   "source": [
    "result = np.min(score, axis=0)\n",
    "print(result)"
   ],
   "id": "11ec319791f60b4f",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[75 81]\n"
     ]
    }
   ],
   "execution_count": 45
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:14.579561Z",
     "start_time": "2025-01-10T08:50:14.576464Z"
    }
   },
   "cell_type": "code",
   "source": [
    "result = np.maximum([-2, -1, 0, 1, 2], 0)\n",
    "print(result)"
   ],
   "id": "59ab9d1fbc99253c",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 0 0 1 2]\n"
     ]
    }
   ],
   "execution_count": 46
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:14.621567Z",
     "start_time": "2025-01-10T08:50:14.618571Z"
    }
   },
   "cell_type": "code",
   "source": [
    "result = np.minimum([-2, -1, 0, 1, 2], 0)\n",
    "print(result)"
   ],
   "id": "553df52f3b3e1faf",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[-2 -1  0  0  0]\n"
     ]
    }
   ],
   "execution_count": 47
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:50:14.636421Z",
     "start_time": "2025-01-10T08:50:14.632570Z"
    }
   },
   "cell_type": "code",
   "source": [
    "result = np.maximum([-2, -1, 4, 1, 2], [1, 2, 3, 4, 5])\n",
    "print(result)"
   ],
   "id": "a72b02afe7256a69",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 4 4 5]\n"
     ]
    }
   ],
   "execution_count": 48
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:51:48.131220Z",
     "start_time": "2025-01-10T08:51:48.126473Z"
    }
   },
   "cell_type": "code",
   "source": [
    "result = np.mean(score)  # 获取所有数据的平均值\n",
    "print(result)\n",
    "result = np.mean(score, axis=0)  # 获取某一行或者某一列的平均值\n",
    "print(result)"
   ],
   "id": "e22ec934ed88a444",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "81.16666666666667\n",
      "[79.         83.33333333]\n"
     ]
    }
   ],
   "execution_count": 49
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:52:44.234398Z",
     "start_time": "2025-01-10T08:52:44.231422Z"
    }
   },
   "cell_type": "code",
   "source": [
    "arr = np.array([[1, 2, 3], [4, 5, 6]])\n",
    "print(arr)\n",
    "print(arr.cumsum(axis=0))"
   ],
   "id": "bac26acec3295a9d",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]]\n",
      "[[1 2 3]\n",
      " [5 7 9]]\n"
     ]
    }
   ],
   "execution_count": 50
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:53:15.636468Z",
     "start_time": "2025-01-10T08:53:15.633456Z"
    }
   },
   "cell_type": "code",
   "source": "print(arr.cumsum(axis=1))",
   "id": "1388c631d54e08eb",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1  3  6]\n",
      " [ 4  9 15]]\n"
     ]
    }
   ],
   "execution_count": 51
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:56:03.909931Z",
     "start_time": "2025-01-10T08:56:03.906014Z"
    }
   },
   "cell_type": "code",
   "source": [
    "result = np.argmin(score, axis=0)\n",
    "res = np.min(score, axis=0)\n",
    "print(result, res)"
   ],
   "id": "a16f4f34f0c99bc9",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2 1] [75 81]\n"
     ]
    }
   ],
   "execution_count": 52
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T08:57:38.717832Z",
     "start_time": "2025-01-10T08:57:38.713168Z"
    }
   },
   "cell_type": "code",
   "source": [
    "result = np.std(score, axis=0)\n",
    "print(result)"
   ],
   "id": "fb6061705b4451e1",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2.94392029 3.29983165]\n"
     ]
    }
   ],
   "execution_count": 53
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T09:51:47.239588Z",
     "start_time": "2025-01-10T09:51:47.235815Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a = np.array([[1, 2], [3, 4]])\n",
    "b = np.array([[5, 6], [7, 8]])\n",
    "print(np.concatenate((a, b), axis=0))\n",
    "print('-' * 50)\n",
    "print(np.concatenate((a, b), axis=1))"
   ],
   "id": "1f6208c6fea74f5e",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2]\n",
      " [3 4]\n",
      " [5 6]\n",
      " [7 8]]\n",
      "--------------------------------------------------\n",
      "[[1 2 5 6]\n",
      " [3 4 7 8]]\n"
     ]
    }
   ],
   "execution_count": 56
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T09:52:39.443171Z",
     "start_time": "2025-01-10T09:52:39.439158Z"
    }
   },
   "cell_type": "code",
   "source": [
    "c = np.array([[9, 10], [11, 12]])\n",
    "print(np.concatenate((a, b, c), axis=1))"
   ],
   "id": "aad6558514ca64fa",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1  2  5  6  9 10]\n",
      " [ 3  4  7  8 11 12]]\n"
     ]
    }
   ],
   "execution_count": 57
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T09:55:09.894945Z",
     "start_time": "2025-01-10T09:55:09.890935Z"
    }
   },
   "cell_type": "code",
   "source": "print(np.stack((a, b, c), axis=2).shape)",
   "id": "f0b86f0b7ce3472b",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2, 2, 3)\n"
     ]
    }
   ],
   "execution_count": 59
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T10:07:18.165581Z",
     "start_time": "2025-01-10T10:07:18.161751Z"
    }
   },
   "cell_type": "code",
   "source": [
    "arr = np.arange(12).reshape(4, 3)\n",
    "print(arr)\n",
    "print('将数组分为三个大小相等的子数组：b是一个列表')\n",
    "b = np.split(arr, 3, axis=1) \n",
    "print(b)"
   ],
   "id": "eaecdd5401450e87",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2]\n",
      " [ 3  4  5]\n",
      " [ 6  7  8]\n",
      " [ 9 10 11]]\n",
      "将数组分为三个大小相等的子数组：b是一个列表\n",
      "[array([[0],\n",
      "       [3],\n",
      "       [6],\n",
      "       [9]]), array([[ 1],\n",
      "       [ 4],\n",
      "       [ 7],\n",
      "       [10]]), array([[ 2],\n",
      "       [ 5],\n",
      "       [ 8],\n",
      "       [11]])]\n"
     ]
    }
   ],
   "execution_count": 60
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T10:08:44.419021Z",
     "start_time": "2025-01-10T10:08:44.415968Z"
    }
   },
   "cell_type": "code",
   "source": "print(b[0].shape)",
   "id": "2fad10f26fa46e43",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(4, 1)\n"
     ]
    }
   ],
   "execution_count": 62
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T10:15:13.546737Z",
     "start_time": "2025-01-10T10:15:13.543083Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a = np.nan\n",
    "b = np.inf\n",
    "print(a, type(a))\n",
    "print(b, type(b))"
   ],
   "id": "c87f206175a23fa1",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "nan <class 'float'>\n",
      "inf <class 'float'>\n"
     ]
    }
   ],
   "execution_count": 63
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T10:15:53.502747Z",
     "start_time": "2025-01-10T10:15:53.498746Z"
    }
   },
   "cell_type": "code",
   "source": [
    "print(np.nan == np.nan)\n",
    "print(np.inf == np.inf)\n",
    "print(np.nan == np.inf)\n",
    "print(True == 1)\n",
    "print(False == 0)\n",
    "np.nan + 1"
   ],
   "id": "3c3348451ec9b87f",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n",
      "False\n",
      "True\n",
      "True\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "nan"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 65
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-10T10:19:15.700115Z",
     "start_time": "2025-01-10T10:19:15.695049Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t = np.arange(24, dtype=float).reshape(4, 6)\n",
    "t[3, 4] = np.nan\n",
    "t[2, 4] = np.nan\n",
    "print(t)\n",
    "print('-' * 50)\n",
    "print(t != t)\n",
    "print('-' * 50)\n",
    "print(np.count_nonzero(t != t)) "
   ],
   "id": "91ee74835622bb9",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.  1.  2.  3.  4.  5.]\n",
      " [ 6.  7.  8.  9. 10. 11.]\n",
      " [12. 13. 14. 15. nan 17.]\n",
      " [18. 19. 20. 21. nan 23.]]\n",
      "--------------------------------------------------\n",
      "[[False False False False False False]\n",
      " [False False False False False False]\n",
      " [False False False False  True False]\n",
      " [False False False False  True False]]\n",
      "--------------------------------------------------\n",
      "2\n"
     ]
    }
   ],
   "execution_count": 66
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "6efef38369e2114f"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
